<style type="text/css">

	body {
		background-color: white;
	}

	.cdalogo {

		background-image: url("resources/sample_bg.png");
		background-repeat: repeat-y;
		height: 360px;
		color: #f5f5f5;
		padding-bottom: 20px;
	}

	.spacer200 {
		height: 200px;
	}

	.dsTest {
		font-size: 24px;
		font-weight: bold;
		color: white;
	}

	table#testTable th {
		font-size: 22px;
		font-weight: normal;
		color: black;
		font-family: Verdana, Helvetica, sans-serif;
	}

	div.desc p {

		font-family: Verdana, Helvetica, sans-serif;
		font-size: 12px;
	}

	#testTable {
		width: 100%;
		font-family: Verdana, Helvetica, sans-serif;
		font-size: 11px;
	}

	#testTable tr {
		height: 20px;
	}

	.logo {
		padding-top: 20px;
		text-align: center;
		font-family: Verdana, Helvetica, sans-serif;
		font-size: 12px;
	}

	#testTable tr td:nth-child(1) {
		font-family: monospace;
		font-size: 12px;
	}

	#testTable tr td:nth-child(4) {
		text-align: center;
	}

	#testTable td.testPending {
		font-style: italic;
		color: blue
	}

	#testTable td.testPassed {
		font-style: italic;
		color: green
	}

	#testTable td.testFailed {
		font-style: italic;
		color: red
	}


</style>

<link type="text/css" href="../cda/static/blueprint/screen.css" rel="stylesheet" />
<div class="webdetailsHead">
	<div class="webdetailsLogo">
		<a href="http://www.webdetails.pt/ctools/cda.html" target="_blank"></a>
	</div>
	<div class="buttoncontact ">
		<a href="mailto:portugal.leads@hitachivantara.com" title="Contact Hitachi Vantara directly here.">Get in Touch</a>
	</div>
</div>
<div class="container">
	<div class="span-23 clearfix cdalogo">
		<div class="span-18 clearfix last">

			<div class="span-18 clearfix last" style="height: 30px;">
				&nbsp;
			</div>

			<div class="span-6 clearfix prepend-1">
				Version ${project.version}
			</div>
			<div class="span-8 append-3 cdaDesc desc last">
				<p> CDA is the <b>Data Access component</b> developed for Pentaho </p>
				<p> Here you can not only access the available datasources but also use it
					as a test page and reference to the way CDA works </p>
			</div>


			<div class="span-18 prepend-1 clearfix last dsTest">
				Datasource Test
			</div>

		</div>

		
		<div class="logo">
			<a id="about" href="/pentaho/api/repos/cda/static/about.html">About</a>

		</div>


	</div>

	<div class="span-22 prepend-1 clearfix last">

		<table id="testTable" cellpadding="0" cellspacing="0">
			<tr>
				<th>Access method</th>
				<th>Description</th>
				<th>Sample</th>
				<th>Result</th>
			</tr>
		</table>

	</div>

</div>

<div class="webdetailsFooter">
	<div class="webdetailsFooterCtools">
		<a href="https://community.hitachivantara.com/s/topic/0TO1J0000017kVNWAY/ctools" target="_blank"></a>
	</div>
</div>

<script language="javascript" type="text/javascript">
	var components = [];

</script>

<script language="javascript" type="text/javascript">

	function load() {
		Dashboards.init(components);
	}

	load();

	// To add test cases, just edit this array

  var testCases = [
    {
      type: "sql.jdbc",
      desc: "Sql query over a jdbc datasource",
      url: webAppPath + "/plugin/cda/api/doQuery?dataAccessId=1&path=/public/plugin-samples/cda/cdafiles/sql-jdbc.cda",
      expectedCols: 4,
      expectedRows: 3
    },
    {
      type: "sql.jndi",
      desc: "Sql query over a jndi datasource",
      url: webAppPath + "/plugin/cda/api/doQuery?dataAccessId=1&path=/public/plugin-samples/cda/cdafiles/sql-jndi.cda",
      expectedCols: 4,
      expectedRows: 2
    },
    {
     type: "sql.stringarray.jndi",
     desc: "Sql query with string array over a jndi datasource",
     url: webAppPath + "/plugin/cda/api/doQuery?dataAccessId=1&path=/public/plugin-samples/cda/cdafiles/sql-stringArray-jndi.cda",
     expectedCols: 2,
     expectedRows: 48
    },
    {
      type: "mondrian.jdbc",
      desc: "Mdx query over a jdbc mondrian connection",
      url: webAppPath + "/plugin/cda/api/doQuery?dataAccessId=1&path=/public/plugin-samples/cda/cdafiles/mondrian-jdbc.cda",
      expectedCols: 4,
      expectedRows: 3
    },
    {
      type: "mondrian.jndi",
      desc: "Mdx query over a jndi mondrian connection",
      url: webAppPath + "/plugin/cda/api/doQuery?dataAccessId=1&path=/public/plugin-samples/cda/cdafiles/mondrian-jndi.cda",
      expectedCols: 4,
      expectedRows: 3
    },
    {
      type: "mondrian.jdbc (denormalized)",
      desc: "Denormalized Mdx query over a jdbc mondrian connection",
      url: webAppPath + "/plugin/cda/api/doQuery?dataAccessId=1&path=/public/plugin-samples/cda/cdafiles/denormalized-mondrian-jdbc.cda",
      expectedCols: 4,
      expectedRows: 6
    },
    {
      type: "mondrian.jndi (denormalized)",
      desc: "Denormalized Mdx query over a jndi mondrian connection",
      url: webAppPath + "/plugin/cda/api/doQuery?dataAccessId=1&path=/public/plugin-samples/cda/cdafiles/denormalized-mondrian-jndi.cda",
      expectedCols: 5,
      expectedRows: 6
    },
    {
      type: "olap4j",
      desc: "Mdx query over a olap4j connection",
      url: webAppPath + "/plugin/cda/api/doQuery?dataAccessId=1&path=/public/plugin-samples/cda/cdafiles/olap4j.cda",
      expectedCols: 4,
      expectedRows: 1
    },
    /*{
type: "olap4j.jndi",
desc: "Mdx query over a olap4j connection",
url: "../cda/doQuery?dataAccessId=1&path=/plugin-samples/cda/cdafiles/olap4j-jndi.cda",
expectedCols: 4,
expectedRows: 1
},*/
    {
      type: "kettle",
      desc: "Kettle transformation",
      url: webAppPath + "/plugin/cda/api/doQuery?dataAccessId=1&path=/public/plugin-samples/cda/cdafiles/kettle.cda",
      expectedCols: 4,
      expectedRows: 1
    },
    {
      type: "metadata",
      desc: "Mql query over a metadata connection",
      url: webAppPath + "/plugin/cda/api/doQuery?dataAccessId=1&path=/public/plugin-samples/cda/cdafiles/metadata.cda",
      expectedCols: 2,
      expectedRows: 198
    },
    {
      type: "scripting",
      desc: "Scripting data access",
      url: webAppPath + "/plugin/cda/api/doQuery?dataAccessId=1&path=/public/plugin-samples/cda/cdafiles/scripting.cda",
      expectedCols: 5,
      expectedRows: 4
    },
    {
      type: "scripting (json object)",
      desc: "Scripting data access using a json object",
      url: webAppPath + "/plugin/cda/api/doQuery?dataAccessId=1&path=/public/plugin-samples/cda/cdafiles/json-scripting.cda",
      expectedCols: 5,
      expectedRows: 4
    },
    {
      type : "xpath",
      desc : "Xpath data access over XML file",
      url : webAppPath + "/plugin/cda/api/doQuery?dataAccessId=1&path=/public/plugin-samples/cda/cdafiles/xpath.cda",
      expectedCols : 2,
      expectedRows : 1
    },
    {
      type: "Compound join",
      desc: "Joining 2 different datasets",
      url: webAppPath + "/plugin/cda/api/doQuery?dataAccessId=3&path=/public/plugin-samples/cda/cdafiles/compoundJoin.cda",
      expectedCols: 5,
      expectedRows: 12
    },
    {
      type: "Compound Union",
      desc: "Appending two different unions",
      url: webAppPath + "/plugin/cda/api/doQuery?dataAccessId=3&path=/public/plugin-samples/cda/cdafiles/compoundUnion.cda",
      expectedCols: 2,
      expectedRows: 4
    }
  ];

	// Init table

	// Build code to execute

	var Caller = Base.extend({
		idx : -1,
		testInfo : {},

		constructor : function(idx) {
			this.idx = idx;
			this.testInfo = testCases[idx];

			this.init();
		},

		init : function() {
			// Add this line to the table
			var sampleFile = this.testInfo.url.match(/cdafiles\/(.*)/)[0];
			$("#testTable").append("<tr><td>" + this.testInfo.type + "</td><td>" + this.testInfo.desc + "</td><td><a href='javascript:showFile(\"" + sampleFile + "\")'>" + sampleFile + "</a></td><td class='testResult testPending'><img src=\"resources/testing.png\" /></td></tr>");
		},

		makeCall : function() {
			var myself = this;
			$.getJSON(this.testInfo.url, function(data) {
				myself.verifyData(data);
			});

		},

		verifyData : function(data) {

			var valid = true;
			var statusText = "";
			var statusImage = "";
			var cssClass;

			if (data.resultset.length != this.testInfo.expectedRows) {
				valid = false;
				statusText += "Unexpected number of rows; ";
			}
			if (data.metadata.length != this.testInfo.expectedCols) {
				valid = false;
				statusText += "Unexpected number of columns; ";
			}

			if (valid) {
				statusText = "";
				statusImage = "<img src=\"resources/ok.png\" />"
				cssClass = "testPassed";
			} else {
				cssClass = "testFailed";
			}

			// Update status
			var statusCell = $("#testTable tr:eq(" + (this.idx + 1) + ") td:eq(3)");
			statusImage.length > 0 ? statusCell.html(statusImage) : statusCell.text(statusText);
			statusCell.removeClass("testPending");
			statusCell.addClass(cssClass);

		}
	});

	var showFile = function(link) {
		$.fancybox({
			type : "iframe",
			href : webAppPath + "/plugin/cda/api/getCdaFile?path=/public/plugin-samples/cda/" + link,
			width : $(window).width() - 100,
			height : $(window).height() - 50
		});
		//	GB_show("Source file",webAppPath + "/content/cda/getCdaFile?path=/plugin-samples/cda/" + link, $(window).height() - 50 , $(window).width() - 100);
	}
	// Call it

	for (var i = 0; i < testCases.length; i++) {
		var c = new Caller(i);
		c.makeCall();
	}


</script>

